<template>
  <SuperTable ref="superTableRef" :search="true" :pager="false" border align="center" :columns="columns" :data-request="fetchData" :export-config="{}" header-title="样本溯源" />
</template>

<script setup lang="ts">
import SuperTable from '@/framework/components/core/super-table/super-table.vue';
import { VxeGridPropTypes } from 'vxe-table';
import type { TableColumnItem } from './columns';
import { baseColumns } from './columns';
import { ref } from 'vue';
import { message } from 'ant-design-vue';
import { queryTrace } from '@/api/common/common_data';
import router from '@/router';

/**
 * table
 */
let first = true;
const superTableRef = ref<InstanceType<typeof SuperTable>>();
const columns: TableColumnItem[] = [
  ...baseColumns,
  {
    title: '操作',
    field: '$action',
    hideInSearch: true,
    align: 'center',
    fixed: 'right',
    width: 300,
    actions: ({ row }) => [
      {
        label: '查看',
        onClick: () => {
          console.log(row);
          switch (row.optCode) {
            case 1003:
              // 出库
              router.push({
                name: 'out_manage_detail',
                query: { id: row.billId },
              });
              break;
            case 1005:
              // 入库
              router.push({
                name: 'input_manage_detail',
                query: { id: row.billId },
              });
              break;
            case 1008:
              // 核销
              break;
          }
        },
      },
    ],
  },
];
const fetchData = async (ori: VxeGridPropTypes.ProxyAjaxQueryParams) => {
  let data = superTableRef.value?.getFormModel();
  if (first) return (first = false);
  if (!data.specimenSerial && !data.stockSerial) {
    message.warn('请选择查询条件，条件不允许为空');
    return {
      data: [],
      pageIndex: 1,
      pageSize: 10,
      total: 100,
    };
  }
  let params = {
    ...data,
  };
  const res = await queryTrace(params);
  return {
    data: res.result,
    pageIndex: 1,
    pageSize: 10,
    total: 100,
  };
};
const refreshTableFn = () => {
  superTableRef.value?.refreshTable();
};
</script>

<style scoped lang="less">
.table-search {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 24px 24px 0;
  background: #fff;
}
.search-item {
  display: flex;
  justify-content: flex-start;
  flex: 1;
}
.search-submitButtons {
  display: block;
  margin-bottom: 24px;
  white-space: nowrap;
}
</style>
